package com.nosnow.oss.controller;

import com.nosnow.common.utils.R;
import com.nosnow.oss.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author by bingHeng
 * @version 1.0
 * @Create 2020/4/3 23:54
 */
@RestController
@RequestMapping("/oss/file")
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation(value="上传头像到阿里OSS")
    @PostMapping("uploadOssFile")
    public R uploadOssFile(MultipartFile file) {
        try {
            // 获取上传到oss的路径
            String url = ossService.uploadFileAvater(file);
            return R.ok().data("url", url);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }
}
